
#ifndef PAGE_COM_H
#define PAGE_COM_H

#include <arduino.h>
#include <lvgl.h>

//#define PAGE_ANIM lv_anim_path_overshoot
#define PAGE_ANIM lv_anim_path_ease_in
//===================================================
typedef enum
{
  PAGE_Login = 0,
  PAGE_Menun,
  PAGE_Watch,
  PAGE_MAX
} Page_List_All;

typedef lv_obj_t* (*PageCallbackNew) (void);
typedef void (*PageCallbackFun) (void* p);
typedef void (*PageCallbackEnt) (int key);
typedef struct {
  PageCallbackNew load_cb;
  PageCallbackFun loop_cb;
  PageCallbackFun exit_cb;
  PageCallbackEnt event_cb;
  lv_obj_t* docker;
} page_list_t;

static page_list_t page_list[PAGE_MAX];

//===================================================
void page_manager_init(int ptime);
bool page_manager_reg(uint8_t page_id,
                      PageCallbackNew load_cb,
                      PageCallbackFun loop_cb,
                      PageCallbackFun exit_cb,
                      PageCallbackEnt event_cb);
void page_manager_event(int key);
void page_manager_switch(uint8_t page_id);
void page_manager_loop();

//===================================================
#define REGINTER_PAGE(PAGE_ID, PAGE_NAME)\
  do{\
    page_manager_reg(PAGE_ID, \
                     page_user_##PAGE_NAME##_load,  \
                     page_user_##PAGE_NAME##_loop,  \
                     page_user_##PAGE_NAME##_exit,  \
                     page_user_##PAGE_NAME##_event);\
  }while(0)

//===================================================
lv_obj_t* page_user_login_load(void);
void page_user_login_loop (void* p);
void page_user_login_event(int key);
//---------------------------------------------------
lv_obj_t* page_user_menun_load(void);
void page_user_menun_event(int key);
//---------------------------------------------------
lv_obj_t* page_user_watch_load(void);
void page_user_watch_event(int key);

#endif
